package com.wcz.code.作业调度;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import com.wcz.code.util.Common;

/**
 * Java定时任务
 * 
 * @author 伪尘子
 *
 * 2012-6-18
 */
public class MyTimerTask extends TimerTask{
	
	private static Timer timer;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Calendar calendar=Calendar.getInstance();
		calendar.set(Calendar.HOUR, 5);
		calendar.set(Calendar.MINUTE, 12);
		calendar.set(Calendar.SECOND, 0);
		timer=new Timer();
		MyTimerTask mytask=new MyTimerTask();
		timer.schedule(mytask, calendar.getTime());
		
	}

	/**
	 * 计划任务执行方法
	 */
	@Override
	public void run() {
		
		myservice();//
		exitTimer();//关闭任务
	}
	
	/**
	 * 我的任务内容
	 */
	public void myservice(){
		
		System.out.println(Common.getDate());
	}
	
	
	public void exitTimer(){
		if(!Common.empty(timer))
			timer.cancel();
	}
}
